package com.zzptc.sky.baidudemo.activities;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;

import com.zzptc.sky.baidudemo.R;
import com.zzptc.sky.baidudemo.adapter.BoxAdapter;
import com.zzptc.sky.baidudemo.base.BaseActivity;
import com.zzptc.sky.baidudemo.db.BaiBoxInfoDao;
import com.zzptc.sky.baidudemo.listener.OnRecyclerItemClickListener;
import com.zzptc.sky.baidudemo.utils.BoxCallBack;
import com.zzptc.sky.baidudemo.utils.BoxDecoration;
import com.zzptc.sky.baidudemo.utils.MyApplication;
import com.zzptc.sky.baidudemo.vo.BaiBoxInfo;

import java.util.List;

public class BaiBoxActivity extends BaseActivity{
    private RecyclerView my_rv;
    private List<BaiBoxInfo> listInfo;
    static Activity activity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_bai_box);
        activity=this;
        my_rv = (RecyclerView) findViewById(R.id.my_rv);

        BaiBoxInfoDao dao = MyApplication.getBoxSession().getBaiBoxInfoDao();
        listInfo = dao.loadAll();

        Log.d("11", listInfo.size()+"");

        //设置布局管理器
        GridLayoutManager gl = new GridLayoutManager(this,4);
        my_rv.setLayoutManager(gl);

        //设置适配器
        BoxAdapter boxAdapter = new BoxAdapter(listInfo);
        my_rv.addItemDecoration(new BoxDecoration(this));
        my_rv.setAdapter(boxAdapter);

        //添加拖拽
        ItemTouchHelper.Callback callback = new BoxCallBack(boxAdapter, listInfo);
        ItemTouchHelper helper = new ItemTouchHelper(callback);
        helper.attachToRecyclerView(my_rv);

        //添加 项的点击
//       my_rv.addOnItemTouchListener(new OnRecyclerItemClickListener(my_rv){
//           @Override
//           public void onItemClick(RecyclerView.ViewHolder vh) {
//               super.onItemClick(vh);
//               BaiBoxInfo baiBoxInfo = listInfo.get(vh.getPosition());
////               if (baiBoxInfo.getName().equals("家人守护")){
////                   startActivity(new Intent(BaiBoxActivity.this,FamilyGuardianActivity.class));
////               }
//
//               switch (baiBoxInfo.getName()){
//                   case "家人守护":
//                       startActivity(new Intent(BaiBoxActivity.this,FamilyGuardianActivity.class));
//                       break;
//               }
//           }
//       });
    }

    public static Activity getActivity(){
        return activity;
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_bai_box;
    }
}
